import java.util.ArrayList;
import java.util.List;

class Main {
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        for (int i = 1;i < numRows;i++) {
            List<Integer> preRow = ret.get(i-1);
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);//每一行的第一个为1
            for (int j = 1;j < i;j++){
                int x = preRow.get(j-1) + preRow.get(j);
                curRow.add(x);
            }
            curRow.add(1);//每一行最后一个也为1
            ret.add(curRow);
        }
        return ret;
    }

    public static void main(String[] args) {
        System.out.println(generate(5));
    }
}